package com.frank.easyexcel.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.frank.easyexcel.model.PersonGender;

/**
 * @author 小石潭记
 * @date 2020/10/16 15:53
 * @Description: excel解析 清洗出:前面的key值
 */
public class GenderConverter implements Converter<PersonGender> {

    @Override
    public Class supportJavaTypeKey() {
        return PersonGender.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public PersonGender convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        for (PersonGender gender : PersonGender.values()) {
            if (gender.getCode().equals(cellData.getStringValue().substring(0, 1))) {
                return gender;
            }
        }
        return null;
    }

    @Override
    public CellData convertToExcelData(PersonGender personGender, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return null;
    }
}
